package cn.itcast.domain.vo;

import lombok.Data;

import java.util.List;
@Data
public class PageBean {
    //    1、当前页码
    private int pageNum;
    //    2、每页显示条数
    private int pageSize;
    //    3、每页的数据
    private List list;
    //    4、总条数
    private Long total;
    //    5、总页数
    private int pages;
    //   6、上一页
    private int prePage;
    //    7、下一页
    private int nextPage;
    //    8、起始页码
    private int navigateFirstPage;
    //    9、结束页码
    private int navigateLastPage;
    public PageBean(int pageNum,List list,int pageSize,Long total){
        this.pageNum=pageNum;
        this.list=list;
        this.pageSize=pageSize;
        this.total=total;
        if(total%pageSize==0){
            pages= (int) (total/pageSize);
        }else {
            pages= (int) (total/pageSize)+1;
        }
        if(pageNum<=1){
            prePage=1;
        }else {
            prePage=pageNum-1;
        }
        if(pageNum>=pages){
            nextPage=pages;
        }else {
            nextPage=pageNum+1;
        }
        if(pages<=5){
            navigateFirstPage=1;
            navigateLastPage=pages;
        }else {
            if(pageNum<=3){
                navigateLastPage=5;
                navigateFirstPage=1;
            }else if(pages-pageNum<=2){
                navigateLastPage=pages;
                navigateFirstPage=pages-4;
            }
        }
    }
}
